<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>归还资产</title>
    <link rel="stylesheet" href="../../layui/css/layui.css">
    <link rel="stylesheet" href="../../css/iconfont.css">
    <link rel="stylesheet" href="../../css/base.css">
    <script src="../../js/jquery-1.11.0.js"></script>
    <script src="../../layui/layui.js"></script>
    <script src="../../js/frameAll.js"></script>
    <style>
        .layui-form {
            margin-top: 30px;
        }
    </style>

</head>
<body>
<form class="layui-form" lay-filter="infoForm">
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">名&emsp;&emsp;称 : </label>
            <div class="layui-input-inline shortInput">
                <input type="text" name="content" autocomplete="off" class="layui-input"
                       placeholder="请输入要查询的名称">
            </div>
        </div>
        <div class="layui-inline">
            <button class="layui-btn" lay-submit lay-filter="submitBut">查询</button>
        </div>
    </div>
</form>
<table id="info" lay-filter="back"></table>
<script>
    layui.use(['table', 'form'], function () {
        var table = layui.table,
            form = layui.form;
        var info = {
            content: '',
            back: '',
        };
        //数据表格
        var tableIns = table.render({
            elem: '#info',
            height: 'full-128',
            url: '/fixedAsset/inout/page.do',
            cellMinWidth: '100',
            text: {
                none: 'QAQ没有查到数据，换个条件吧'
            },
            where: info,
            request: {
                pageName: 'pageNo',
                limitName: 'pageSize'
            },
            page: true,
            cols: [[
                {title: '序号', type: 'numbers', width: 80},
                {
                    title: '资产名称', unresize: true, templet: function (res) {
                        return res.zc.zcName;
                    }
                },
                {field: 'comployeeNo', title: '员工编号', unresize: true},
                {
                    title: '员工名称', unresize: true, templet: function (res) {
                        return res.comployee.comployeeName;
                    }
                },
                {field: 'outTime', title: '借出时间', unresize: true},
                {field: 'shouldTime', title: '应还时间', unresize: true},
                {title: '操作', align: "center", toolbar: '#barDemo', unresize: true}
            ]],
            error: function () {
                top.location.href = "../../login.html";
            },
            done: function (res) {
                if (res.message) {
                    noMsg(res.message);
                }
            },
        });
        //查询指定条件的用户
        form.on('submit(submitBut)', function (data) {
            var field = data.field;
            info.content = field.content;
            tableIns.reload({
                page: {curr: 1}
            });
            return false;
        });
        //借出
        table.on('tool(back)', function (obj) {
            var data = obj.data
                , layEvent = obj.event;
            if (layEvent === 'back') {
                layer.confirm('您确定要归还借给员工【' + data.comployee.comployeeName + '】的资产【' + data.zc.zcName + '】吗？', function (index) {
                    //向服务端发送删除指令
                    $.ajax({
                        type: 'Post',
                        url: '/fixedAsset/inout/back.do',
                        data: {no: data.inoutNo},
                        dataType: 'Json',
                        success: function (data) {
                            if (data.code === 0) {
                                yesMsg(data.message);
                                obj.del();
                                layer.close(index);
                            } else {
                                noMsg(data.message);
                            }
                        }
                    });
                });
            }
        });
    });
</script>
<script type="text/html" id="barDemo">
    <a class="layui-btn layui-bg-blue layui-btn-sm" lay-event="back">归还</a>
</script>
</body>
</html>